import {ALLINVOICE} from './mutations-types'
import {invoiceList, modyInvoice, deleteInvoice} from '../../../service/get-data'

export default {
  // 获取所有的发票列表
  async getAllInvoice ({commit}, type) {
    let res = await invoiceList(type = 1)
    if (res.data.resultCode && res.data.resultCode === 2000) {
      commit(ALLINVOICE, res.data.data)
    }
  },
  // 修改,新增发票
  async modInvoice ({dispatch, commit}, obj) {
    let res = await modyInvoice(obj.id, obj.type, obj.title, obj.eleCode)
    if (res.data.resultCode && res.data.resultCode === 2000) {
      await dispatch('getAllInvoice', -1)
      return res
    }
  },
  // 删除发票
  async deleteInvoice ({dispatch, commit}, id) {
    let res = await deleteInvoice(id)
    if (res.data.resultCode && res.data.resultCode === 2000) {
      await dispatch('getAllInvoice', -1)
    }
  }
}
